<template>
    <div class="exlist">
        <Table border :columns="columns" :data="datalist" :loading="tableload"></Table>
        <br/>
        <Button type="primary" v-if="status" @click="addSilde">添加</Button>
        <orh-sidebar v-model="show" :title="pageTitle" cover slot="others">
            <component :is="'Operation'" :teacher_id="teacher_id" :infoId="infoId" @showParent="showParent=>show=showParent" @backList="backList"></component>
        </orh-sidebar>
    </div>
</template>
<script>
    export default {
        props: {
            status: {
                type: [Boolean],
                default: true
            },
            teacher_id: {
                type: [Boolean,String,Number],
                default: false
            },
            user_id: {
                type: [Boolean,String,Number],
                default: false
            }
        },
        components: {
            Operation: resolve => {require(['./Operation.vue'], resolve);},
        },
        data () {
            return {
                columns: [
                    {
                        title: '奖励项目',
                        render: (h, params) => {
                        let name= params.row.name.zh?params.row.name.zh:params.row.name.mn;
                        return h('div', name);
                       
                    },
                    },
                    {
                        title: '奖励金额（万元）',
                        key: 'awardmoney'
                    },
                    {
                        title: '排名',
                        render: (h, params) => {
                            let ranking = params.row.ranking.zh?params.row.ranking.zh:params.row.ranking.mn;
                            return h('div',ranking)
                        }
                    },
                    {
                        title: '获奖年份',
                        key: 'enddate'
                    },
                    {
                        title: '授予机构',
                        render: (h, params) => {
                            let institution = params.row.institution.zh?params.row.institution.zh:params.row.institution.mn;
                            return h('div',institution)
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        render: (h, params) => {
                            let dis=params.row.shenhe = 2 ? false : true
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
                                        disabled:dis
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
                                        this.update(params.row.awqualification_id)
                                        }
                                    }
                                }, '编辑'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small',
                                        disabled:dis
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
                                            this.del = [params.row.awqualification_id]
                                            this.confirm()
                                        }
                                    }
                                }, '删除'),
                            ]);
                        }
                    }
                ],
                datalist:[],
                tableload:false,
                del:[],
                show:false,
                pageTitle:'',
                infoId:null
            }
        },
        methods: {
            /************************************************************
             * 
             * 请求列表数据
             * 
             ************************************************************/
            queryData(){
                this.tableload = true 
                this.$http.get(`api/teacher/v1/awbsqualification/teacherqulist?teacher_id=${this.teacher_id}`)
                .then(val=>{   
                    this.datalist=val.data
                    this.tableload = false            
                })
                .catch(err=>{
                    if(err.code && err.code==422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload = false;
                })
            },  
            /************************************************************
             * 
             * 点击添加
             * 
             ************************************************************/
            addSilde () {
                this.show=true
                this.infoId = false
                this.pageTitle='添加'
            },

            /************************************************************
             * 
             * 点击编辑
             * 
             ************************************************************/
            update(index){  
                this.infoId = index
                this.show=true
                this.pageTitle='修改'
            },

            /************************************************************
             * 
             * 修改添加返回数据更新
             * 
             ************************************************************/
            backList(val){      
                if(val == true){
                    this.show=false
                    this.queryData();
                }
            },
            /************************************************************
             * 
             * 执行删除操作
             * 
             ************************************************************/
            confirm () {
                this.$Modal.confirm({
                    title: '数据删除',
                    content: '<p>您确定要删除这些数据吗?</p>',
                    onOk: () => {
                        this.del = JSON.stringify(this.del)
                        this.tableload = true 
                        this.$http.delete(`api/teacher/v1/awbsqualification/del/${this.del}`)
                        .then(val=>{  
                            this.del=[]
                            this.queryData()    
                            this.$Message.success(val.message);           
                        })
                        .catch(err=>{
                            if(err.code && err.code==422) {
                                this.$Message.error(err.message);
                            }
                            this.del=[]
                            this.tableload = false 
                        })
                    },
                });
            },
        },
        mounted(){
            // 操作列显示不显示  开始
            let arr=''
            if(this.status==false){
                arr=this.columns.pop()
            }else{
                if(arr){
                    this.columns.push(arr[0])
                }
            }
            // 操作列显示不显示  结束
            this.queryData()
        }
    }
</script>
<style lang="less">
@import'./../public.less';
</style>



